package com.toocms.jinjuhang.config

import android.app.Application
import com.shuyu.gsyvideoplayer.cache.CacheFactory
import com.shuyu.gsyvideoplayer.player.PlayerFactory
import com.toocms.tab.configs.IAppConfig
import com.toocms.tab.map.TabMapApi
import com.toocms.tab.network.encrypt.ApiEncryptOption
import com.toocms.tab.share.TabShare
import okhttp3.OkHttpClient
import rxhttp.wrapper.param.Param
import tv.danmaku.ijk.media.exo2.Exo2PlayerManager
import tv.danmaku.ijk.media.exo2.ExoPlayerCacheManager


class AppConfig : IAppConfig {
    override fun getBaseUrl() = Urls.BASE_URL

    override fun getUpdateUrl() = Urls.UPDATE_URL

    override fun getUmengAppkey() = Constants.ThirdPartyInfo.UMENG_APP_KEY

    override fun getUmengPushSecret() = ""

    override fun setOnParamAssembly(param: Param<*>?): Param<*>? {
        param?.add("terminal", "1")
        return param
    }

    override fun getApiEncryptOption(): ApiEncryptOption? {
        return null
    }

    override fun customOkHttp(builder: OkHttpClient.Builder?) {

    }

    override fun isCustomUpdate() = false

    override fun initJarForWeApplication(application: Application?) {
        Region.init(application!!.applicationContext)
        TabMapApi.agreePrivacy(application)
        initializeVideo()
        if(null!=application){
            initializeShare(application)
        }
    }

    /**
     * 初始化播放器
     */
    private fun initializeVideo(){
        //EXOPlayer内核，支持格式更多
        PlayerFactory.setPlayManager(Exo2PlayerManager::class.java)
        //exo缓存模式，支持m3u8，只支持exo
        CacheFactory.setCacheManager(ExoPlayerCacheManager::class.java)
    }


    private fun initializeShare(application:Application){
        TabShare.registerWX(application, Constants.ThirdPartyInfo.WECHAT_APP_KEY, Constants.ThirdPartyInfo.WECHAT_APP_SECRET)
    }
}